package cn.edu.uestc.smgt.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.uestc.smgt.common.QueryBase;
import cn.edu.uestc.smgt.dao.UnitMapper;
import cn.edu.uestc.smgt.pojo.Unit;

@Service
public class UnitService {
	@Autowired
	private UnitMapper unitMapper;

	public List<Unit> getAllUnit() {

		return unitMapper.selectAll();
	}

	public int add(Unit unit) {
		if(unitMapper.selectByPrimaryKey(unit.getId())!=null){
			return 0;
		}
		return unitMapper.insertSelective(unit);
	}

	public int update(Unit unit) {
		return unitMapper.updateByPrimaryKeySelective(unit);
	}

	public int delete(String id) {
		return unitMapper.deleteByPrimaryKey(id);
	}

	public void query(QueryBase querybase) {
		// TODO Auto-generated method stub
		querybase.setTotalRow(unitMapper.size(querybase.getParameters()));
		querybase.setResults(unitMapper.selectBySelectionsAndPage(querybase));
	}

	public Unit getUnitById(String unitId) {
		// TODO Auto-generated method stub
		return unitMapper.selectByPrimaryKey(unitId);
	}
}
